package abd.pr1.Mappers;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import abd.pr1.Models.ComentarioSerie;
import abd.pr1.Models.Genero;

public class GenerosMapper extends AbstractMapper<Genero, Integer>{

	private static final String[] GENEROS_KEY_COLUMN_NAMES = new String[] { "id" };
	private static final String[] GENEROS_COLUMN_NAMES = new String[] { "id","nombre"};
	private static final String GENEROS_TABLE_NAME = "generos";
	
	public GenerosMapper(DataSource ds) {
		super(ds);
	}

	@Override
	protected String getTableName() {
		return GENEROS_TABLE_NAME;
	}

	@Override
	protected String[] getColumnNames() {
		return GENEROS_COLUMN_NAMES;
	}

	@Override
	protected Object[] serializeObject(Genero object) {
		return new Object[] { object.getId(),object.getNombre()};
	}

	@Override
	protected String[] getKeyColumnNames() {
		return GENEROS_KEY_COLUMN_NAMES;
	}

	@Override
	protected Object[] serializeKey(Integer key) {
		return new Object[] { key };
	}

	@Override
	protected Genero buildObject(ResultSet rs) throws SQLException {
		Integer id = rs.getInt("id");
		String nombre = rs.getString("nombre");
		
		return new Genero(id, nombre);
	}

	@Override
	protected Integer getKey(Genero object) {
		return object.getId();
	}

	@Override
	protected boolean hasAutoincrementKey() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	void updateKeys(ResultSet rs, Genero object) throws SQLException {
		Integer id = rs.getInt(1);
		object.setId(id);	
		
	}

	
	
}
